<?php
$this->headTitle('Phân quyền - Sửa','append');
?>
<div class="grid grid_7">
    <div class="box-header">Phân quyền - Sửa</div>
    <div class="box">
        <?php
            if(isset($this->mess)){
                echo '<div class="notification error"><span class="strong">',$this->mess,'</span></div>';
            }
        ?>
        <form id="form" method="post" action="" enctype="multipart/form-data" name="form">
            <dl class="zend_form">
                <div class="row">
                    <label>Role Name:</label>
                    <input type="text" id="roleName" name="roleName" value="<?php echo $this->role_check['roleName']; ?>" class="required w300" minlength="3" maxlenght="255"/>
                </div>
                <!--Project-->
                <div class="row"><br />
                    <label>Dự án:</label>
                    <div class="search-option-wrapper">
                        <fieldset style="padding:10px;margin: 0 auto;border:  1px solid #d5d5d5;">
                            <legend>Dự án : <input type="checkbox" id="check_projects"/> SELECT ALL </legend>
                            <ul class="search-option-check">
                            <?php 
                                foreach ($this->project_list as $p) {
                                    $check = '';
                                    if(in_array($p->projectId, $this->role_project))
                                        $check = ' checked="checked"';
                                    echo "<li><input type='checkbox' name='projects[]' value='" . $p->projectId . "'$check><label>{$p->projectName}</label></li>";
                                }
                            ?>
                            </ul>
                        </fieldset>
                    </div>
                </div>
                <!--Privilege-->
                <div class="row">
                    <label>Quyền:</label>
                    <div class="search-option-wrapper">
                        <fieldset style="padding:10px;margin: 0 auto;border:  1px solid #d5d5d5;">
                            <legend>Quyền : <input type="checkbox" id="check_resources"/> SELECT ALL </legend>
                            <ul class="search-option-check">
                            <?php 
                                foreach ($this->resource_list as $r) { 
                                    $check = '';
                                    if(in_array($r->id, $this->role_resource))
                                        $check = ' checked="checked"';
                            ?>
                                <?php if(($r['id'] == 1)){?>
                                <li>
                                    <input type="checkbox" name="resources[]" value="<?php echo $r['id'] ?>"<?php echo $check;?>/>
                                    <label><a id="link_<?php echo $r['id'] ?>" class="viewDetail" href="#viewDetail"><?php echo $r['resourceName'] ?></a></label>
                                </li>
                                <?php }else{ ?>
                                <li>
                                    <input type="checkbox" name="resources[]" value="<?php echo $r['id'] ?>"<?php echo $check;?>/>
                                    <label><?php echo $r['resourceName'] ?></label>
                                </li>
                                <?php }?>
                            <?php } ?>
                            </ul>
                        </fieldset>
                        <div style="display: none;">
                            <div id="viewDetail" style="padding: 10px 20px 20px 20px;background: #F4F4F4;">
                                <div class="search-option-wrapper">
                                    <div><h1>Chọn thuộc tính cần hiển thị<br /><br /></h1></div>
                                    <fieldset style="padding:10px;margin: 0 auto;border:  1px solid #d5d5d5;">
                                        <legend><input type="checkbox" id="check_views"/> SELECT ALL </legend>
                                        <ul style="width: 600px;" class="search-option-check">
                                            <?php 
                                                foreach($this->views_list as $k=>$v){ 
                                                    $check = '';
                                                    if(in_array($k, $this->role_option))
                                                        $check = ' checked="checked"';
                                            ?>
                                                <li>
                                                    <input type="checkbox" name="views[]" value="<?php echo $k; ?>"<?php echo $check;?>/>
                                                    <label><?php echo $v['header'] ;?></label>
                                                </li>
                                            <?php } ?>
                                        </ul>
                                        <br /><br />
                                    </fieldset>
                                    <input type="button" id="viewDetailClose" value="Đóng" style="padding: 4px 15px;"/>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <input value="Lưu lại" class="button" type="submit" />
                    <input value="Reset" class="button" type="reset"/>
                </div>
            </dl>
        </form>
    </div>
    <style>
        ul li input[type="checkbox"]{float: left; margin: 5px 5px 5px 0;}
    </style>
</div>
<script type="text/javascript" src="js/jquery.validate.js"></script>
<script>
    $(document).ready(function(){
        $("#form").validate();
        $("#check_projects").click(function(){
            $("input[name^='projects']").prop('checked', this.checked);
        });
        $("#check_resources").click(function(){
            $("input[name^='resources']").prop('checked', this.checked);
        });
        $("#check_views").click(function(){
            $("input[name^='views']").prop('checked', this.checked);
        });
        $(".viewDetail").fancybox({
            'autoScale'			: true,
            'transitionIn'		: 'none',
            'transitionOut'		: 'none'
        });
        $("#viewDetailClose").click(function(){
            $.fancybox.close();
        });
        
    });
</script>
